package com.night.icm.service.business.mapper;

import com.night.icm.model.business.NotificationInformationDTO;
import com.night.icm.persistence.business.entity.NotificationInformation;
import org.mapstruct.*;

import java.util.List;

/**
 * NotificationInformationMapper
 *
 * @author Liao ZhiYong
 * @date 2020/4/1
 */
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface NotificationInformationMapper {
    /**
     * DTO转实体
     *
     * @param dto DTO
     * @return 实体
     */
    @Mapping(target = "files", ignore = true)
    NotificationInformation toEntity(NotificationInformationDTO dto);

    /**
     * 实体转DTO--供findById使用
     *
     * @param entity 实体
     * @return DTO
     */
    NotificationInformationDTO toDTO(NotificationInformation entity);

    /**
     * 实体转DTO--供分页查询使用
     *
     * @param save 实体
     * @return DTO
     */
    @Named("toDtoByPage")
    @Mapping(target = "files", ignore = true)
    NotificationInformationDTO toDtoByPage(NotificationInformation save);

    /**
     * 实体集转为DTO集
     *
     * @param entities 实体集
     * @return DTO集
     */
    @IterableMapping(qualifiedByName = "toDtoByPage")
    List<NotificationInformationDTO> toList(List<NotificationInformation> entities);

    /**
     * 更新一个已经存在的实体数据
     *
     * @param dto    存在的DTO
     * @param entity 更新后的实体
     */
    @Mapping(target = "files", ignore = true)
    void updateEntity(NotificationInformationDTO dto, @MappingTarget NotificationInformation entity);
}
